import java.io.*;
import java.util.Properties;


// 配置，全局变量，最先初始化
public class Property {
    public static String runMode;
    public static String ddl;
    public static String primaryDbURL;
    public static String standbyDbURL;
    public static String username;
    public static String password;
    public static int pkgTypeNum;
    public static int produceParallel;
    public static int consumeParallel;
    public static int tablePartCount;
    public static int runMins;
    public static String logFile;
    
    public static boolean buildMode;
    
    public static boolean init(String[] args) throws FileNotFoundException, IOException {
        if (args.length == 0) {
            System.out.println("ERROR: no parameter");
            return false;
        }
        
        if (args[0].equals("build")) {
            runMode = args[0];
            buildMode = true;
        } else if (args[0].equals("run")) {
            buildMode = false;
            runMode = args[0];
        } else {
            System.out.println("ERROR: only support 'build' and 'run', current is " + args[0]);
            return false;
        }
        
        String propertyPath = "config_gauss.properties";
        if (args.length > 1) {
            propertyPath = args[1];
        }
        
        // 获取配置
        Properties prop = new Properties();
        InputStream in = new FileInputStream(propertyPath);
        prop.load(in);
        Property.ddl = prop.getProperty("ddl");
        Property.primaryDbURL = prop.getProperty("primaryDbURL");
        Property.standbyDbURL = prop.getProperty("standbyDbURL");
        Property.username = prop.getProperty("username");
        Property.password = prop.getProperty("password");
        Property.pkgTypeNum = Integer.valueOf(prop.getProperty("pkgTypeNum"));
        Property.produceParallel = Integer.valueOf(prop.getProperty("produceParallel"));
        Property.consumeParallel = Integer.valueOf(prop.getProperty("consumeParallel"));
        Property.tablePartCount = Integer.valueOf(prop.getProperty("tablePartCount"));
        Property.runMins = Integer.valueOf(prop.getProperty("runMins"));
        Property.logFile= prop.getProperty("logFile");
        return true;
    }
};
